'use strict';
const Controller = require('egg').Controller;
const { responseFormat, responseHandleFormat, tokenDisabled } = require('../public/js/utils');

class PageController extends Controller {

  // 查询所有的页面路由地址
  async findAllPage() {
    const { ctx } = this;
    // 从请求头中获取token
    const token = ctx.request.header.token;
    const user = await ctx.service.token.findUserByToken(token);
    if (!user) {
      ctx.body = tokenDisabled();
      return;
    }
    const { list } = await ctx.service.page.findAllPage(user);
    ctx.body = responseFormat(true, list);
  }

  async saveEditPage() {
    const { ctx } = this;
    const { id, father, icon, label, path, redirect, sort } = ctx.request.body;
    const result = await ctx.service.page.saveEditPage(id, father, icon, label, path, redirect, sort);
    ctx.body = responseHandleFormat(result);
  }
}
module.exports = PageController;
